package com.bite.book.config;

import com.bite.book.mode.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

//进行统一异常的处理；
@Slf4j
@ControllerAdvice
@ResponseBody
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handler(Exception e){
        log.error("发生异常"+e);
        return Result.fail("内部错误，请联系管理员");
    }
    @ExceptionHandler
    public Result handler(NullPointerException e){
        log.error("发生异常"+e);
        return Result.fail("空指针异常，请联系管理员");
    }
    @ExceptionHandler
    public Result handler(IndexOutOfBoundsException e){
        log.error("发生异常"+e);
        return Result.fail("数组越界异常，请联系管理员");
    }
}
